﻿using Md.Api.Model;
using Md.Api.Model.Web.MdProduct.Request;
using Md.Api.Service.Web.MdProduct;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;

namespace Md.Api.Controllers.Web;
/// <summary>
/// PC产品管理
/// </summary>
[ApiController]
[Produces("application/json")]
[Route("md-api/web/product")]
public class MdProductWebController : ControllerBase
{
    /// <summary>
    /// 获取体验产品列表服务
    /// </summary>
    public GetMdProductExperienceListWebService getMdProductExperienceListWebService { get; set; }
    /// <summary>
    /// 获取体验产品列表
    /// </summary>
    /// <param name="model">请求实体</param>
    /// <returns>ResponseMessageModel</returns>
    [Route("experienceList"), HttpPost, AllowAnonymous]
    public async Task<ResponseMessageModel> GetMdProductExperienceListWeb([FromBody] RequestGetMdProductExperienceListWebModel model)
    {
        return await Task.Run(() => getMdProductExperienceListWebService.Execute(model));
    }

    /// <summary>
    /// 分页获取产品列表服务
    /// </summary>
    public GetMdProductPageListWebService getMdProductPageListWebService { get; set; }
    /// <summary>
    /// 分页获取产品列表
    /// </summary>
    /// <param name="model">请求实体</param>
    /// <returns>ResponseMessageModel</returns>
    [Route("listPage"), HttpPost, AllowAnonymous]
    public async Task<ResponseMessageModel> GetMdProductPageListWeb([FromBody] RequestGetMdProductPageListWebModel model)
    {
        return await Task.Run(() => getMdProductPageListWebService.Execute(model));
    }

    /// <summary>
    /// 通过编号获取产品详情服务
    /// </summary>
    public GetMdProductByIdWebService getMdProductByIdWebService { get; set; }
    /// <summary>
    /// 通过编号获取产品详情
    /// </summary>
    /// <param name="productId">产品编号</param>
    /// <param name="signModel">加密实体</param>
    /// <returns>ResponseMessageModel</returns>
    [HttpGet("{productId}"), AllowAnonymous]
    public async Task<ResponseMessageModel> GetMdProductByIdWeb(long productId, [FromQuery] RequestSignModel signModel)
    {
        var model = new RequestGetMdProductByIdWebModel();

        model.ProductId = productId;
        model.TimesTamp = signModel.TimesTamp;
        model.Mac = signModel.Mac;
        model.Ip = signModel.Ip;
        model.Sign = signModel.Sign;
        model.Version = signModel.Version;
        model.Token = signModel.Token;

        return await Task.Run(() => getMdProductByIdWebService.Execute(model));
    }
}

